package top.kaoshanji.p1ch08a;

/**
 * 代码清单-p1ch08a-179页a：使用公共对象来实现组合
 * author kaoshanji
 * ^_^
 * create time 2025/3/9 16:18
 */
public class Car { // 汽车

    public Engine engine = new Engine();
    public Wheel[] wheels = new Wheel[4];
    public Door left = new Door();
    public Door right = new Door();

    public Car() {
        for (int i = 0; i < 4; i++) {
            wheels[i] = new Wheel();
        }
    }

    public static void main(String[] args) {
        Car car = new Car();
        car.left.window.rollup(); // 将左边窗口关上
        car.wheels[0].inflate(72); // 将第一个轮子充气

    }


}

class Engine { // 发动机
    public void start() {}
    public void rev() {}
    public void stop() {}
}

class Wheel { // 轮子
    public void inflate(int psi) {}
}

class Window { // 门窗
    public void rollup() {}
    public void rolldown() {}
}

class Door { // 门
    public Window window = new Window();
    public void open() {}
    public void close() {}
}